using System.IO;
using UnityEditor;
using UnityEditor.ProjectWindowCallback;
using UnityEngine.Rendering;
using UnityEngine;

public class VUniversalRenderPipelineAsset: RenderPipelineAsset
{
    [SerializeField]
    private bool _srpBatcher = true;

    [SerializeField]
    private ShadowSetting _shadowSetting = new ShadowSetting();
    [SerializeField]
    PostFXSettings _postFXSettings = default;
    
    
    public bool enableSrpBatcher{
        get{
            return _srpBatcher;
        }
    }

 
    public ShadowSetting shadowSetting{
        get{
            return _shadowSetting;
        }
    }
    public PostFXSettings postFXSettings{
        get{
            return _postFXSettings;
        }
    }
    // [Range(10,100)]
    // public int ShadowDistance=20;
    [SerializeField] 
    private VScriptableRendererData[] m_RendererDataList = new VScriptableRendererData[1];
    public VScriptableRenderer scriptableRenderer
    {
        get
        {
            return _scriptableRenderer;
        }
    }

    private VScriptableRenderer _scriptableRenderer;
    public enum RendererType
    {
        VForwardRenderer,
    }

    public static string packagePath;
    protected override RenderPipeline CreatePipeline()
    {
        _scriptableRenderer = m_RendererDataList[0].InternalCreateRenderer();
        return new VUniversalRenderPipeline(this);
        
    }
    
    

    
    
    
    
    
    #region Create Pipeline Asset
#if UNITY_EDITOR
    public static VUniversalRenderPipelineAsset Create(VScriptableRendererData rendererData = null)
    {
        var instance = CreateInstance<VUniversalRenderPipelineAsset>();

        return instance;
    }


    internal class CreateCustomUniversalPipelineAsset : EndNameEditAction
    {
        public override void Action(int instanceId, string pathName, string resourceFile)
        {
            packagePath = pathName;
            AssetDatabase.CreateAsset(Create(CreateRendererAsset(pathName, RendererType.VForwardRenderer)), pathName);
        }
    }

    [MenuItem("Assets/Create/V Rendering/Render Pipeline/V Pipeline Asset (Forward Renderer)", priority = CoreUtils.Priorities.assetsCreateRenderingMenuPriority)]
    static void CreateUniversalPipeline()
    {
        ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, CreateInstance<CreateCustomUniversalPipelineAsset>(),
            "VUniversalRenderPipelineAsset.asset", null, null);
    }

    static VScriptableRendererData CreateRendererAsset(string path, RendererType type, bool relativePath = true)
    {
        VScriptableRendererData data = CreateRendererData(type);
        string dataPath;
        if (relativePath)
            dataPath =
                $"{Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path))}_Renderer{Path.GetExtension(path)}";
        else
            dataPath = path;
        AssetDatabase.CreateAsset(data, dataPath);
        return data;
    }

    static VScriptableRendererData CreateRendererData(RendererType type)
    {
        switch (type)
        {
            case RendererType.VForwardRenderer:
                return CreateInstance<VForwardRendererData>();
            default:
                return CreateInstance<VForwardRendererData>();
        }
    }
}

#endif
#endregion

